package com.mqb.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ClientHandlersInitializer extends ChannelInitializer<SocketChannel> {

    private static final Logger log = LoggerFactory.getLogger(ClientHandlersInitializer.class);

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        log.info("starting connect to server...");
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new LengthFieldBasedFrameDecoder(65535, 0, 4, 0, 4));
        //pipeline.addLast(new ClientIdleStateTrigger());
        pipeline.addLast(new StringEncoder());

        pipeline.addLast(new StringDecoder());
        // 处理服务器发送的消息
        pipeline.addLast(new ClientMessageReceiveHandler());

    }
}
